//
//  UIImageView+TZCategory.swift
//  SimpleTZ
//
//  Created by wangfeng on 2020/7/13.
//  Copyright © 2020 davis. All rights reserved.
//

import UIKit
import Kingfisher
extension UIImageView {
    
    func tz_setImage(urlString: String?, placeholderName: String? = nil) {
          let placeholder: UIImage? = placeholderName == nil ? nil : UIImage(named: placeholderName!)
          tz_setImage(url: urlString, placeholder: placeholder)
      }
      
      func tz_setImage(url: String?, placeholder:UIImage? = nil) {
          var imageUrl: URL?
          if let imageString = url {
              imageUrl = URL(string: imageString)
          } else {
              imageUrl = nil
          }
          self.kf.setImage(with: imageUrl, placeholder: placeholder, options: nil, progressBlock: nil, completionHandler: nil)
      }
    
    
    
    
    
    
    
    func tz_setImage(urlString: String?, placeholder: UIImage? = nil, option: KingfisherOptionsInfo? = nil, progressBlock: DownloadProgressBlock? = nil, completionHandler: CompletionHandler? = nil) {
        var imageUrl: URL?
        if let iamgeString  = urlString {
            imageUrl = URL(string: iamgeString)
        } else {
            imageUrl = nil
        }
        
        self.kf.setImage(with: imageUrl, placeholder: placeholder, options: option, progressBlock: { (receivedSize, totalSize) in
            progressBlock?(receivedSize,totalSize)
        }) { (image, error, cacheType, url) in
            completionHandler?(image,error,cacheType,url)
        }
    }
}
